<?php
//连接数据库
mysql_connect('127.0.0.1:3308','root','');
mysql_select_db('test');
mysql_query('set names utf8');
	$search = $_POST['search']?:'';
	$field = $_POST['field']?:'';
	$where = '';
	if($search && $field){
		$where.=" and `{$field}` like '%{$search}%'";
	}
$query = mysql_query("select count(*) c from subjects where 1 {$where}");
$arr = mysql_fetch_array($query);
$total = $arr['c'];

	$data['pageSize'] = isset($_POST['pageSize']) ? $_POST['pageSize'] : 10;
	$data['total'] = $total;
	$start = 0;
	
	if($_POST['pageNumber']){
		$start = ($_POST['pageNumber']-1)*$data['pageSize'];
	}
	if($search){
		$start = 0;
	}
	$sql = "";
	$query = mysql_query("select * from subjects where 1 {$where} limit {$start},{$data['pageSize']}");
	
	$i=0;
	while($row= mysql_fetch_array($query)){
		$data['rows'][$i]= $row;
		$i++;
	}	
	
	header('Content-type: application/json');
	echo json_encode($data);exit();
